package com.anthonybennis.blender.client.pages.bestwebsites;

import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.event.dom.client.TouchStartEvent;
import com.google.gwt.event.dom.client.TouchStartHandler;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.ui.client.widget.touch.TouchPanel;

/**
 * 
 * @author abennis
 */
public class BestWebsiteWidgetFactory
{
	private final Frame _frame;
	/**
	 * 
	 * @param frame
	 */
	public BestWebsiteWidgetFactory(Frame frame)
	{
		_frame = frame;	
	}
	
	/**
	 * 
	 * @param data
	 * @return
	 */
	public Widget create(final WebpageTileData data) 
	{
		TouchPanel webPageButtonPanel = new TouchPanel(); 
		webPageButtonPanel.getElement().getStyle().setCursor(Cursor.POINTER);
		webPageButtonPanel.setStyleName("best-websites-nav-panel");
		/*
		 * Image
		 */
		Image image = new Image(data.getImage());
		image.setStyleName("best-websites-nav-image-label");
		webPageButtonPanel.add(image);
		
		/*
		 * Text Label
		 */
		final Label navigationLabel = new Label();
		navigationLabel.setStyleName("best-websites-nav-label");
		navigationLabel.setText(data.getDisplayName());
		webPageButtonPanel.add(navigationLabel);
		/*
		 * For Mouse events.
		 */
		webPageButtonPanel.addTouchStartHandler(new TouchStartHandler() {
			
			@Override
			public void onTouchStart(TouchStartEvent event) {
				_frame.setUrl(data.getURL());
			}
		});
		
		webPageButtonPanel.addTapHandler(new TapHandler() {
			
			@Override
			public void onTap(TapEvent event) {
				_frame.setUrl(data.getURL());
			}
		});
		
		
		
		return webPageButtonPanel;
	}
}
